package com.pine.manager.pineframework.convertors;

import com.pine.common.beans.pineframework.request.SysDictQueryRequest;
import com.pine.common.beans.pineframework.request.SysDictSaveOrUpdateRequest;
import com.pine.common.beans.pineframework.response.SysDictQueryResponse;
import com.pine.common.convertor.EntityConvertor;
import com.pine.common.convertor.QueryConvertor;
import com.pine.common.convertor.SaveConvertor;
import com.pine.dao.pineframework.constants.StatusEnum;
import com.pine.dao.pineframework.entity.SysDict;
import com.pine.manager.pineframework.bo.SysDictBo;
import com.pine.manager.pineframework.query.SysDictQuery;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 字典表 转换器
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public abstract class SysDictConvertor implements EntityConvertor<SysDict, SysDictBo>,
        QueryConvertor<SysDictBo, SysDictQuery, SysDictQueryRequest, SysDictQueryResponse>,
        SaveConvertor<SysDictBo, SysDictSaveOrUpdateRequest> {

    @Override
    public abstract SysDict entityBoToEntity(SysDictBo sysDictBo);

    @Override
    public abstract SysDictBo entityToEntityBo(SysDict sysDict);

    @Override
    public abstract SysDictQueryResponse entityBoToQueryResponse(SysDictBo sysDictBo);

    @Override
    public abstract SysDictQuery queryRequestToQuery(SysDictQueryRequest queryRequest);

    @Override
    public abstract List<SysDict> entityBoToEntity(List<SysDictBo> entityBo);

    @Override
    public abstract List<SysDictBo> entityToEntityBo(List<SysDict> entity);


    @AfterMapping
    public void afterMappingEntityBoToEntity(@MappingTarget SysDict sysDict, SysDictBo sysDictBo) {
        // entityBoToEntity() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToEntity()
    }

    @AfterMapping
    public void afterMappingEntityToEntityBo(@MappingTarget SysDictBo sysDictBo, SysDict sysDict) {
        // entityToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityToEntityBo()
    }

    @AfterMapping
    public void afterMappingQueryRequestToQuery(@MappingTarget SysDictQuery sysDictQuery, SysDictQueryRequest sysDictQueryRequest) {
        // queryRequestToQuery() 内部其它代码执行完之后，最后会自动执行 afterMappingQueryRequestToQuery()
    }

    @AfterMapping
    public void afterMappingEntityBoToQueryResponse(@MappingTarget SysDictQueryResponse sysDictQueryResponse, SysDictBo sysDictBo) {
        // entityBoToQueryResponse() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToQueryResponse()
    }

    public StatusEnum integerToStatusEnum(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return StatusEnum.of(code);
    }

    public Integer statusEnumToInteger(StatusEnum statusEnum) {
        if (Objects.isNull(statusEnum)) {
            return null;
        }
        return statusEnum.getCode();
    }

}
